<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title><?=$da['title']?></title>
    <link rel="stylesheet" type="text/css" href="mode/weui/weui.min.css"/>
    <link rel="stylesheet" type="text/css" href="web/res/fontawesome/css/font-awesome.min.css">
    <link rel="stylesheet" type="text/css" href="webmain/css/rui.css">
    <script src = './upload/data/jquery.min.js'></script>
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <script type="text/javascript" src="js/js.js"></script>
    <script type="text/javascript" src="js/jswx.js"></script>
    <script type="text/javascript" src="js/base64-min.js"></script>
    <script type="text/javascript" src="web/res/js/jquery-rockupload.js"></script>
    <script  src="https://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
    <script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp&libraries=convertor,geometry"></script>
    <style>

    </style>
    <script>
        var kqrs = <?=json_encode($kqrs);?>,kqors = <?=json_encode($kqors);?>,kqallrs=[],isgzh = <?=$isgzh?>;
        var customer = <?=json_encode($customer);?>

        js.servernow = '<?=$rock->now?>';
        var infoWin,marker,circle;
        var choose = 0;
        var imgpath = '';
        var addr = '';
        var customerId;

        var label='',accuracy=0,latitude='',longitude='',kqjuli=-1,addbo = true;
        apiready = function(){
            initbodyss()
        }

        var html= '';

        window.onload=function(){

             for(var i = 1; i<customer.length+1;i++){
                 var obj = customer[i -1 ];
                 html+='<li id="'+ obj.id +'" onclick="choosecus(this)"><a href="#">'+ obj.name +'</a></li>'
             }
             html +='<li role="separator" class="divider"></li>'
             html += '<li id="0" onclick="choosecus(this)"><a href="#">取消</a></li>'
             $("#ulhtml").html(html);

        }

        function choosecus(that){

            var a=document.getElementById ("span1");

            if(that.id == 0){
                a.innerHTML = "选择拜访客户";

            }else{
                a.innerHTML = that.innerHTML;
            }
            customerId = that.id;

        }


        function initbody(){
            if(js.request('ftype')!='app')initbodyss();
            initupload();
        }
        function initbodyss(){
            js.getsplit();
            if(isgzh==1){
                js.jssdkwxgzh();
            }else{
                js.jssdkwixin();
            }
            showtimessabc();
            var lata = js.getoption('latlongedu','24.504332,118.141136,12').split(',');
            if(!lata[2])lata[2]=12;
            scale 	= parseFloat(lata[2]);
            var center = new qq.maps.LatLng(parseFloat(lata[0]), parseFloat(lata[1]));
            map = new qq.maps.Map(document.getElementById('container'),{
                center: center,
                zoom: scale
            });

            if(kqrs){
                kqallrs.push(kqrs);
                var i,kqrsa,enddt,precision;
                for(i in kqors)kqallrs.push(kqors[i]);

                for(i=0;i<kqallrs.length;i++){
                    kqrsa = kqallrs[i];
                    enddt = new qq.maps.LatLng(parseFloat(kqrsa.location_x), parseFloat(kqrsa.location_y));
                    new qq.maps.Marker({map: map,position:enddt});
                    precision = parseFloat(kqrsa.precision);
                    if(precision>0){
                        new qq.maps.Circle({
                            map:map,
                            center:enddt,
                            radius:precision,
                            fillColor:new qq.maps.Color(255,0,0, 0.3),
                            strokeColor:new qq.maps.Color(255,0,0, 0.5),
                            strokeWeight:1
                        });
                    }
                }
            }
            geocoder = new qq.maps.Geocoder({
                complete : function(result){
                    js.msg();
                    addbo	 = true;
                    scale	 = map.getZoom();
                    js.setoption('latlongedu',''+latitude+','+longitude+','+scale+'');
                    clearTimeout(dwtimeer);
                    dwbool		= false;
                    var center 	= result.detail.location;
                    map.setCenter(center);
                    var address = result.detail.address;
                    var dzarr 	= result.detail.addressComponents;
                    address 	= ''+dzarr.province+''+dzarr.city+''+dzarr.district+''+dzarr.street+'';
                    if(dzarr.streetnumber)address+=dzarr.streetnumber;
                    label 		= address+'';
//                    if(accuracy>0)address+='(精确'+accuracy+'米)';


                    showinfo(center ,accuracy, '定位成功<br>地址：'+address+'');

                    addr = address;

                    var i,kqrsa,enddt,juli;
                    for(i=0;i<kqallrs.length;i++){
                        kqrsa = kqallrs[i];
                        enddt = new qq.maps.LatLng(parseFloat(kqrsa.location_x), parseFloat(kqrsa.location_y));
                        juli  = parseInt(qq.maps.geometry.spherical.computeDistanceBetween(center, enddt));
                        if(juli<0)juli = 0-juli;
                        if(kqrsa['iswgd']=='1')juli=0; //无固定位置的
                        kqallrs[i]['kqjuli'] = juli;
                        kqjuli = juli;
                    }
                }
            });
        }

        function showtimessabc(){

            var dt = js.serverdt('H:i:s');
            var weeks = ["星期日","星期一","星期二","星期三","星期四","星期五","星期六"]
            var d=new Date()
            var day=d.getDate()
            var month=d.getMonth() + 1
            var year=d.getFullYear()
            var week = weeks[d.getDay()]

            var hour = d.getHours();

            var min = d.getMinutes();

            var sec = d.getSeconds();

            var time = year + "-" + month + "-" + day + '&nbsp&nbsp&nbsp&nbsp' +week;

            if (hour >= 1 && hour <= 9) {
                hour = "0" + hour;
            }

            if (min >= 1 && min <= 9) {
                min = "0" + min;
            }

            if (sec >= 1 && sec <= 9) {
                sec = "0" + sec;
            }

            var currentTime = hour + ":" + min  + ":" + sec

            $('#dwdiv').html(time);
            $('#timess').html(dt);

            setTimeout('showtimessabc()',1000);

        }


        js.jssdkcall  = function(bo){
            dingweidak();
        }
        function showinfo(center ,fw, str){
            if(!infoWin)infoWin = new qq.maps.InfoWindow({
                map: map
            });
            infoWin.open();
            infoWin.setContent(str);
            infoWin.setPosition(center);

            if(!marker)marker= new qq.maps.Marker({
                map: map
            });
            marker.setPosition(center);
            if(!circle)circle=new qq.maps.Circle({
                map:map,
                strokeWeight:1
            });
            circle.setCenter(center);
            circle.setRadius(parseFloat(fw));
        }
        var dwbool=false,dwtimeer;
        function dingweidak(){
            if(dwbool)return;
            dwbool = true;
            chaoshi();
            if(js.jssdkstate != 1){
                htmldingw();
                return;
            }
            var msg = '微信定位中...';
            if(js.isqywx)msg='企业微信定位中...';
            js.msg('wait',msg);
            wx.getLocation({
                type: 'gcj02',
                success: function (res){
                    js.setmsg('');
                    clearTimeout(dwtimeer);
                    latitude 	= res.latitude;
                    longitude 	= res.longitude;
                    scale		= map.getZoom();
                    accuracy 	= parseFloat(res.accuracy);
                    js.msg('wait','定位成功，获取位置信息...');
                    var center 	= new qq.maps.LatLng(latitude, longitude);
                    geocoder.getAddress(center);

                },
                error:function(){
                    js.msg('msg','微信定位失败，请重试');
                    js.jssdkstate = 2;
                    clearTimeout(dwtimeer);
                }
            });
        }
        function chaoshi(){
            clearTimeout(dwtimeer);
            dwtimeer = setTimeout(function(){
                js.msg('msg','定位超时，请重新定位');
                js.jssdkstate = 2;
                dwbool=false;
            },20*1000);
        }
        function htmldingw(){
            if(appobj1('startLocation','appbacklocation')){
                js.msg('wait','原生app定位中...');
                return;//原生定位成功
            }
            if(api.appName){
                baidingwei();//百度定位
                return;
            }

            if(!navigator.geolocation){
                js.msg('msg','不支持浏览器定位');
                clearTimeout(dwtimeer);
            }else{
                js.msg('wait','浏览器定位中...');
                navigator.geolocation.getCurrentPosition(showPosition,showError,{
                    enableHighAccuracy: true,
                    timeout: 19000,
                    maximumAge: 3000
                });
            }
        }
        appbacklocation=function(res){
            js.setmsg('');
            clearTimeout(dwtimeer);
            latitude 	= res.latitude;
            longitude 	= res.longitude;
            scale		= map.getZoom();
            accuracy 	= parseFloat(res.accuracy);
            js.msg('wait','定位成功，获取位置信息...');
            var center 	= new qq.maps.LatLng(latitude, longitude);
            geocoder.getAddress(center);
        }
        function showError(error){
            clearTimeout(dwtimeer);dwbool=false;
            js.setmsg('');
            var msg='无法定位';
            switch(error.code){
                case error.PERMISSION_DENIED:
                    msg="用户拒绝对获取地理位置的请求。"
                    break;
                case error.POSITION_UNAVAILABLE:
                    msg="位置信息是不可用的。"
                    break;
                case error.TIMEOUT:
                    msg="请求用户地理位置超时。"
                    break;
                case error.UNKNOWN_ERROR:
                    msg="未知错误。"
                    break;
            }
            var url = '<?=URLY?>view_wxgzh.html';
            js.wx.alert('浏览器无法定位？请看<a href="'+url+'">[帮助设置]</a>',function(){
                js.location(url);
            });
            js.msg('msg', msg);
        }
        function showPosition(position){
            js.msg('');
            clearTimeout(dwtimeer);
            var res 	= position.coords;
            latitude 	= res.latitude;
            longitude 	= res.longitude;
            scale		= map.getZoom();
            accuracy 	= parseFloat(res.accuracy);
            js.msg('wait','定位成功，获取位置信息...');
            var center = new qq.maps.LatLng(parseFloat(latitude), parseFloat(longitude));
            translate(center, 1);
        }
        function translate(center,type){
            qq.maps.convertor.translate(center,type,function(res){
                latitude 	= res[0].lat;
                longitude 	= res[0].lng;
                geocoder.getAddress(res[0]);
            });
        }
        //保存
        var adddkjlcs = {},upfileid='';

        function adddkjl(){


            wx.uploadImage({
                localId: imgpath, // 需要上传的图片的本地ID，由chooseImage接口获得
                isShowProgressTips: 1, // 默认为1，显示进度提示
                success: function (res) {
                    var serverId = res.serverId; // 返回图片的服务器端ID


                    $.ajax({
                        type: 'POST',
                        //url: "http://localhost/oa/public_html/?d=we&m=wq&a=wqdw",
                         url: "http://oa.wxlion.com/?d=we&m=wq&a=wqdw",
                        data: {
                            imagepath: serverId,
                            explain: $('#explain').val(),
                            address:addr,
                            customer:customerId

                        },
                        datatype: "json",
                        success: function(data) {

                            var url='index.php?d=we&m=wq&a=wqcx';

                            js.location(url);

                        },
                        //调用出错执行的函数
                        error: function(error1) {


                        }
                    });

                },
                fail: function (res) {


                }
            });


        }

        function adddkjlok(ids){
            upfileid= ids;
            adddkjl(adddkjlcs.lx,adddkjlcs.ss,adddkjlcs.sm,true);
        }
        function adddkjlsss(){
            if(dwbool){js.wx.alert('正在定位，稍后在添加');return;}
            if(latitude==''){js.wx.alert('定位没有成功，不能添加');return;}
            if(!addbo){js.wx.alert('已保存过了，请重新定位后在保存');return;}
            js.wx.prompt('保存定位','请输入说明(选填)：',function(text){
                adddkjl(0,'保存', text);
            });
        }
        function baidingwei(){
            var baiduLocation = api.require('baiduLocation');
            js.msg('wait','定位中...');
            baiduLocation.startLocation({
                accuracy: '500m',
                filter: 1,
                autoStop: true
            },function(ret, err) {
                if (ret.status) {
                    latitude 	= ret.latitude;
                    longitude 	= ret.longitude;
                    scale		= map.getZoom();
                    accuracy 	= 0;
                    var center 	= new qq.maps.LatLng(latitude, longitude);
                    translate(center, 3);
                }else {
                    js.msg('msg','定位失败');
                    js.jssdkstate = 2;
                    clearTimeout(dwtimeer);
                }
            });
        }

        function showdw(id){
            var d = dwarr[id];
            if(isempt(d.location_x)){js.wx.alert('没有位置信息无法查看');return;}
            if(js.jssdkstate!=1 || isempt(d.location_x)){
                var url = '?d=main&m=kaoqin&a=location&id='+d.id+'';
                js.location(url);
            }else{
                wx.openLocation({
                    latitude: parseFloat(d.location_x), // 纬度，浮点数，范围为90 ~ -90
                    longitude: parseFloat(d.location_y), // 经度，浮点数，范围为180 ~ -180。
                    name: '定位地址', // 位置名
                    address: d.label, // 地址详情说明
                    scale: parseFloat(d.scale)
                });
            }
        }
        function addkaoqin(){
            if(!kqrs){js.wx.alert('没有设置定位考勤位置');return;}
            if(dwbool){js.wx.alert('正在定位，稍后在添加');return;}
            if(latitude=='' || kqjuli==-1){js.wx.alert('定位没有成功，不能添加');return;}

            var i,kqrsa,slju,sljus,iskqbo=false;
            for(i=0;i<kqallrs.length;i++){
                kqrsa 	= kqallrs[i];
                slju	= parseFloat(kqrsa.precision);
                sljus	= parseFloat(kqrsa.kqjuli);
                if(sljus<=slju)iskqbo = true;
            }
          //  if(!iskqbo){js.wx.alert('当前位置距离考勤点有'+kqjuli+'米,考勤设置误差不能超过'+slju+'米，故不能添加考勤打卡！');return;}

            if(!addbo){js.wx.alert('已打卡过了，请重新定位后在打卡');return;}

            if(!choose){js.wx.alert('请拍照上传');return;}

            if(!$('#explain').val().length){js.wx.alert('请填写说明');return;}

            adddkjl();

        }

        var ispzs = false;
        function initupload(){
            upfaceobj=$.rockupload({
                uptype:'image',
                inputfile:'cameraInput',
                fileview:'fileview',
                autoup:false,
                onsuccess:function(f,str){
                    var a=js.decode(str);

                },
                onchange:function(f){
                    $('#paizhaoimg').parent().show();
                    get('paizhaoimg').src = f.imgviewurl;
                    get('pzbtnicons').className='icon-remove';
                    ispzs = true;
                },
                onprogress:function(f,bl){
                    $('#tisssa').html('上传图中('+bl+'%)');
                },
                allsuccess:function(far, ids){
                    adddkjlok(ids);
                }
            });
        }

        function paizhao(){
            if(!ispzs){
                upfaceobj.click({uptype:'image'});
            }else{
                upfaceobj.clear();
                $('#paizhaoimg').parent().hide();
                get('paizhaoimg').src = 'images/noimg.jpg';
                get('pzbtnicons').className='icon-camera';
                ispzs	= false;
            }
        }
        function changfile(o1){
            upfaceobj.change(o1);
        }
        function showimgs(o1){
            $.imgview({'url':o1.src,'ismobile':true});
        }

        function chooseimage(){

            wx.chooseImage({
                count: 9, // 默认9
                sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
                sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
                success: function (res) {

                    var localIds = res.localIds; // 返回选定照片的本地ID列表，localId可以作为img标签的src属性显示图片
                    imgpath = localIds[0];

                    $("#camer").html(' <image onclick="chooseimage()" id="photo" style="width: 60px; height: 60px; margin-right: 20px " src='+ imgpath +'></image> <div style="padding: 10px;width: 40px; height:40px;background-color:rgb(250,247,254);"> <image onclick="chooseimage()" id="photo" style="width: 40px; height: 40px;  " src="./images/camer.png"></image> </div>');
                    choose = 1;

                }
            });
        }
        function previewimage(that){


           // alert($("#photo").attr("src"));
            wx.previewImage({
                current: that.src, // 当前显示图片的http链接
                urls: [that.src] // 需要预览的图片http链接列表
            });
        }

    </script>
    <style>

        html, body{ margin:0; height:100%; }
        .addbtnss{position:absolute;right:calc(50% - 40px);bottom:10px;width:80px;height:80px; background-color: rgb(27,205,138);z-index:1;border-radius:50%;font-size:14px;color:black;text-align:center;}

    </style>
</head>


<body>
<?php if($showheader==1){?>
<div>
    <div class="r-header">
        <div class="r-header-text" onclick="location.reload()" id="header_title"><?=$da['title']?></div>
        <span onclick="js.back()" class="r-position-left r-header-btn"><i class="icon-chevron-left"></i></span>
    </div>
    <div class="blank50"></div>
</div>
<?php }?>

<div style="height: 100%">

    <div style="width:100%;height:45%;position:relative">
        <div style="display:none;position:absolute;z-index:2;left:1px;top:1px;width:120px;height:80px;overflow:hidden"><img width="100%" onclick="showimgs(this)" id="paizhaoimg" src="images/noimg.jpg"></div>
        <div id="container" style="position:absolute;width:100%;height:100%;"></div>

    </div>


    <div style="display:none" id="fileview"></div>



        <div style="display: flex; flex-direction: row;padding-top: 10px; margin-left: 10px;">

            <div id="dwdiv" style="font-size: 8vm; margin-top: 5px"></div>

            <div class="dropdown" style="margin-left: 30px;">
                <button class="btn btn-default dropdown-toggle" type="button" style="min-width: 155px;" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">

                    <span style="color: black" id="span1">选择拜访客户</span>
                    <span class="caret"></span>
                </button>
                <ul id="ulhtml" class="dropdown-menu" aria-labelledby="dropdownMenu1" style="min-width: 110px;">

                </ul>


            </div>

        </div>



        <div style="background-color: white;height: 150px; padding: 10px;"  >

            <textarea id="explain" style="width: 100%;height: 80px; border: 1px darkgray solid; box-shadow:0px 0px 0px rgba(0,0,0,0);-webkit-appearance:none; padding: 5px;border-radius: 5px; box-sizing: border-box;font-size: 15px" placeholder="请在此处输入说明..."></textarea>


           <div style="flex-direction: row;display: flex;" id ='camer'>


               <div style="width: 40px; height:40px;background-color:rgb(250,247,254);">

                   <image onclick="chooseimage()" id="photo" style="width: 40px; height: 40px;  " src="./images/camer.png"></image>
               </div>


           </div>



        </div>



        <div class="addbtnss" onclick="addkaoqin()"><div style="margin-top:15px" id="kaoqin">签到<br><span id="timess"><?=date('H:i:s')?></span></div></div>

    </div>
    <div class="blank10"></div>
</div>
<script type="text/javascript" src="web/res/js/jquery-imgview.js"></script>
</body>
</html>